#pragma once
#include <iostream>
#include "Protocol.hpp"

using namespace std;

class Calculate
{
public:
    Calculate()
    {
    }
    Response Excute(const Request &req)
    {
        Response res(0, 0);
        switch (req._oper)
        {
        case '+':
        {
            res._result = req._x + req._y;
            break;
        }
        case '-':
        {
            res._result = req._x - req._y;
            break;
        }
        case '*':
        {
            res._result = req._x * req._y;
            break;
        }
        case '/':
        {
            if(req._y==0)
            {
                res._code = 1;//除0错误
                break;
            }
            res._result = req._x / req._y;
            res._code = 0;
            break;
        }

        case '%':
        {
            if(req._y==0)
            {
                res._code = 2;//模0错误
                break;
            }
            res._result = req._x % req._y;
            res._code = 0;
            break;
        }
        default:
        {
            res._code=3;//非法操作
            break;
        }
        }
        return res;
    }
    ~Calculate()
    {
    }

private:
};